﻿using System;
using System.IO;
using System.Web.UI;
using SVTTranslateTextEngine.Core;
using SVTTranslateTextEngine.TestWeb.SVTTranslateTextEngine;

namespace SVTTranslateTextEngine.TestWeb
{
    public partial class TestTextToFile : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnTranslate_Click(object sender, EventArgs e)
        {
            DateTime startDate = DateTime.Now;
            var input = new TextInputParam
                            {
                                szFromLang = ddlFrom.SelectedValue,
                                szToLang = ddlTo.SelectedValue,
                                szFromText = txtSrc.Text,
                                szVendorName = "GOOGLE"
                            };
            ToFileResult reVal = new TTWebService().TranslateTextToFile(input);
            if (string.IsNullOrEmpty(reVal.szErrorMessage) && string.IsNullOrEmpty(reVal.szExceptionMessage))
            {
                txtTrg.Text = new FileAccessHelper().ReadTextContext(reVal.szToFilename);
                lblMsg.Text = "The target context file path is :<br />" +
                              reVal.szToFilename + "<br /><br />";
                if (File.Exists(reVal.szToFilename))
                    File.Delete(reVal.szToFilename);
            }
            else
                lblMsg.Text = reVal.szErrorMessage + (reVal.szExceptionMessage ?? "") + "<br /><br />";
            lblMsg.Text += "Uses Time : [" + (DateTime.Now - startDate).TotalMilliseconds + "]ms";
        }
    }
}